package com.qf.servlet;

import com.qf.Enity.User;
import com.qf.service.UserserviceImpl;
import com.qf.service.Userservidce;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/regist")
public class RegistServlet extends HttpServlet {
    private Userservidce userService = new UserserviceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String phone = req.getParameter("phone");
        String sex = req.getParameter("sex");
        User user = new User(username,password,phone,sex);
        boolean isok = userService.regist(user);
       /* resp.setContentType("text/html;charset=utf-8");*/
        PrintWriter out = resp.getWriter( );
        if (isok) {
            resp.sendRedirect("/login1.html");
        } else {
            out.write("<html>");
            out.write("<head>");
            out.write("<title>提示</title>");
            out.write("</head>");
            out.write("<body>");
            out.write("<h1>注册失败</h1>");
            out.write("</body>");
            out.write("</html>");
        }
    }
}
